/** 
* 文 件 名:MainActivity.java
* Copyright (C) 2007-2012:杭州希禾信息技术有限公司 版权所有 
* 创 建 人:胡浩
* 日    期:2012-3-20 下午7:38:34
* 修 改 人: 
* 日   期:
* 修改描述:
* 描   述:TODO
*/

package net.seehealth.healthpad.ui;

import java.util.ArrayList;
import java.util.List;

import net.seehealth.healthpad.Constants;
import net.seehealth.healthpad.Constants.Main;
import net.seehealth.healthpad.R;
import net.seehealth.healthpad.application.adapter.TaskAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

/**
 * @className MainActivity
 * @author 胡浩
 * @description 主界面
 * @date 2012-3-20 下午7:38:34
 */
public class MainActivity extends BaseActivity {

	/** 日期控件 **/
	private TextView mDataView;

	/** 个人头像 **/
	private ImageView mPhotoView;

	/** 个人姓名 **/
	private TextView mNameView;

	/** 我的任务列表 **/
	private ListView mTaskListView; 

	/** 健康记录 **/
	private ImageView mHealthRecordView;

	/** 健康应用 **/
	private ImageView mHealthAppView;

	/** 膳食指导 **/
	private ImageView mDietaryGuideView;

	/** 运动建议 **/
	private ImageView mSportsAdviceView;

	/** 未读消息数 **/
	private Button mMessageCountBtn;

	/** 天气预报 **/
	private ImageView mWeatherView;

	/** 健康监测 **/
	private ImageView mHealthMonitorView;

	/** 在线互动  **/
	private ImageView mOnlineInteractiveView;

	/** 消息条数 **/
	private TextView mMessageCountView;

	/** 天气预报视图 **/
	private TextView mWeather1View;
	private TextView mWeather2View;

	/** 天气预报更新时间 **/
	private TextView mUpdateTimeView;

	/** 系统公告 **/
	private ImageButton mInfosBtn;

	/** 健康宣教 **/
	private ImageView mMessageBtn;

	/** 本机设置 **/
	private ImageButton mSettingsBtn;

	/** 我的任务适配器 **/
	private TaskAdapter mTaskAdapter;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// 初始化数据
		initData();

		// 初始化视图
		initView();

	}
	
	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onPause() {
		super.onPause();
		
	}
	
	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {

		return super.onKeyDown(keyCode, event);
	}

	/**
	 * 初始化界面
	 */
	private void initView(){
		setContentView(R.layout.main);

		mDataView = (TextView) findViewById(R.id.tv_main_date);
		mPhotoView = (ImageView) findViewById(R.id.iv_main_photo);
		mNameView = (TextView) findViewById(R.id.tv_main_name);
		mTaskListView = (ListView) findViewById(R.id.lv_task_list);
		mTaskListView.setAdapter(mTaskAdapter);

		mHealthRecordView = (ImageView) findViewById(R.id.iv_main_health_record);
		mHealthAppView = (ImageView) findViewById(R.id.iv_main_health_app);
		mDietaryGuideView = (ImageView) findViewById(R.id.iv_main_dietary_guide);
		mSportsAdviceView = (ImageView) findViewById(R.id.iv_main_sports_advice);
		mMessageCountBtn = (Button)findViewById(R.id.btn_main_online_interactive_count);
		mWeatherView = (ImageView) findViewById(R.id.iv_main_weather_icon);
		mHealthMonitorView = (ImageView) findViewById(R.id.iv_main_shm);
		mOnlineInteractiveView = (ImageView)findViewById(R.id.iv_main_online_interactive);
		mMessageCountView = (TextView)findViewById(R.id.tv_main_message_count);
		mWeather1View = (TextView) findViewById(R.id.tv_main_weather1);
		mWeather2View = (TextView) findViewById(R.id.tv_main_weather2);
		mUpdateTimeView = (TextView) findViewById(R.id.tv_main_updatetime);
		mInfosBtn = (ImageButton) findViewById(R.id.ib_main_info);
		mMessageBtn = (ImageButton) findViewById(R.id.ib_main_message);
		mSettingsBtn = (ImageButton) findViewById(R.id.ib_main_setting);

		mHealthRecordView.setOnClickListener(clickListener);
		mHealthAppView.setOnClickListener(clickListener);
		mDietaryGuideView.setOnClickListener(clickListener);
		mSportsAdviceView.setOnClickListener(clickListener);
		mHealthMonitorView.setOnClickListener(clickListener);
		mOnlineInteractiveView.setOnClickListener(clickListener);
		mNameView.setOnClickListener(clickListener);
		mInfosBtn.setOnClickListener(clickListener);
		mSettingsBtn.setOnClickListener(clickListener);
		mMessageBtn.setOnClickListener(clickListener);

		mDataView.setText("2012-02-23 星期四   12:20");
		mPhotoView.setBackgroundResource(R.drawable.main_head_image);
		mNameView.setText("李琳琳");
		mMessageCountBtn.setText("+3");
		mMessageCountView.setText("3");
		mWeatherView.setBackgroundResource(R.drawable.main_temperature_sun);
		mWeather1View.setText("北京18℃");
		mWeather2View.setText("12C~18℃     晴");
		mUpdateTimeView.setText("更新时间   22:18");
	}

	/**
	 * 初始化数据
	 */
	private void initData(){
		mTaskAdapter = new TaskAdapter(mContext);
		mTaskAdapter.setData(getTaskList());

		DisplayMetrics metric = new DisplayMetrics();
        getWindowManager().getDefaultDisplay().getMetrics(metric);

        Constants.Screen.WIDTH = metric.widthPixels;  	// 屏幕宽度（像素）
        Constants.Screen.HEIGHT = metric.heightPixels;  // 屏幕高度（像素）
        Constants.Screen.DENSITY = metric.density;  	// 屏幕密度(0.75/1.0/1.5)
        Constants.Screen.DENSITYDPI = metric.densityDpi;// 屏幕密度DPI(120/160/240)
	}

	/**
	 * 得到任务集合
	 * @return
	 */
	private List<String> getTaskList() {

		List<String> list = new ArrayList<String>();
		list.add("请在今日内及时上传血压数据，血糖数据1");
		list.add("请在今日内及时上传血压数据，血糖数据2");
		list.add("请在今日内及时上传血压数据，血糖数据3");
		list.add("请在今日内及时上传血压数据，血糖数据4");

		return list;
		
	}

	/**
	 * 点击事件
	 */
	View.OnClickListener clickListener = new View.OnClickListener() {
		
		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.iv_main_shm:										// 自助检测
				Intent intent = new Intent(MainActivity.this, SelfDetectionActivity.class);
				startActivity(intent);
				break;
			case R.id.iv_main_health_record:							// 健康记录
				Intent intent2 = new Intent(MainActivity.this, HealthRecordsActivity.class);
				startActivity(intent2);
				break;	
			case R.id.iv_main_dietary_guide:							// 膳食指导
				mealGuidePop();
				break;
			case R.id.iv_main_sports_advice:							// 运动建议
				sportsAdvicePop();
				break;
			case R.id.ib_main_info:										// 系统公告
				Intent intent3 = new Intent(MainActivity.this, MainListActivity.class);
				intent3.putExtra(Main.TYPE, Main.ANNOUNCE);
				startActivity(intent3);
				break;
			case R.id.ib_main_message:									// 健康宣教
				Intent message = new Intent(MainActivity.this, MainListActivity.class);
				message.putExtra(Main.TYPE, Main.MESSAGE);
				startActivity(message);
				break;
			case R.id.ib_main_setting:									// 本机设置
				Intent intent4 = new Intent(MainActivity.this, MachineSettingsActivity.class);
				startActivity(intent4);
				break;
			case R.id.iv_main_health_app:								// 健康应用
				Intent intent5 = new Intent(MainActivity.this, HealthApplicationsActivity.class);
				startActivity(intent5);
				break;
			case R.id.iv_main_online_interactive:   
				remoteConsultationPop();
				break;
			default:
				break;
			}
		}
	};
	
	/**
	 * 膳食指导弹出框
	  * @author HuHao
	  * @date 2012-4-5 下午9:07:34
	 */
	private void mealGuidePop() {
		Intent intent = new Intent(MainActivity.this, MealGuideActivity.class);
		startActivity(intent);
		overridePendingTransition(R.anim.popshow_anim, R.anim.pophidden_anim);
	}
	
	/**
	 * 运动建议弹出框
	  * @author HuHao
	  * @date 2012-4-5 下午9:07:34
	 */
	private void sportsAdvicePop() {
		Intent intent = new Intent(MainActivity.this, SportsAdviceActivity.class);
		startActivity(intent);
//		overridePendingTransition(R.anim.push_up_in, R.anim.push_up_out);
	}
	
	private void remoteConsultationPop(){
		Intent intent = new Intent(MainActivity.this, RemoteConsultationActivity.class);
		startActivity(intent);
	//	overridePendingTransition(R.anim.push_up_in, R.anim.push_up_out);
	}
	
	
	/**
	 * 关闭按钮监听
	 */
	OnClickListener click = new OnClickListener() {
		
		@Override
		public void onClick(View v) {
			closePopWindow();
		}
	};
	
}
